package com.qxzn.module.home.adapter;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qxzn.app.bean.AlbumPictureBean;
import com.qxzn.app.page.interfaces.MyInterface;
import com.qxzn.module.home.R;
import com.qxzn.module.home.R2;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AlbumPictureAdapter extends RecyclerView.Adapter<AlbumPictureAdapter.ViewHolder> {

    private Activity activity;
    private List<AlbumPictureBean> dataList;
    private AlbumPictureBean item;
    private MyInterface.AlbumPictureClickListener pictureClick;

    public AlbumPictureAdapter(Activity activity, List dataList) {
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_album_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
        holder.tvDate.setText(item.getTime());
        AlbumPictureGridAdapter adapter = new AlbumPictureGridAdapter(activity, item.getResulthead());
        adapter.setParentPosition(position);
        adapter.setPictureClickListener(pictureClick);
        holder.rvGridPicture.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    public void setPictureClick(MyInterface.AlbumPictureClickListener pictureClick) {
        this.pictureClick = pictureClick;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.tv_date)
        TextView tvDate;
        @BindView(R2.id.rv_grid_picture)
        RecyclerView rvGridPicture;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            rvGridPicture.setLayoutManager(new GridLayoutManager(view.getContext(), 4));
        }
    }
}
